*
* Replication file for Experiment 2 analysis in:
*
* On the Merits of Separate Spaces: Why Institutions Isolate Cooperation and Division Tasks
* By Scott E. Bokemper and Gregory A. Huber
* Political Behavior
*
* This is a stata .do file  
* Version 1.0, May 24, 2023

* Note: This code uses this Stata version of the outreg package for table export
* net install sg97_4.pkg
which outreg
* Should return the following:
*! Write formatted regression output to a text file
*! version 4.10  30nov2011 by John Luke Gallup (jlgallup@pdx.edu)

capture log close
clear
set more off
log using Experiment2AnalysisLog.txt, text replace

use experiment2_analysisdataset.dta, replace

* First description, own (unimplemented) proposed split in Division Game
tab DG_Own_Proposal

* Second analysis, effect of either unfair division on policy adoption, ignoring everything else
tab T_DG_Partner_Given PG_proposal , row
regress PG_proposal i.T_DG_Partner_Given

* Setup regression analysis
gen T_DGGot0=T_DG_Partner_Given==0
label var T_DGGot0 "Division Game Got 0"
gen T_PGNet10=T_policynetpayoff==10
label var T_PGNet10 "Policy Game Nets 10"
gen T_PGNet20=T_policynetpayoff==20
label var T_PGNet20 "Policy Game Nets 20"
gen T_SamePerson=T_partnertype==1
label var T_SamePerson "Partner is Same Person"
gen T_SameGroup=T_partnertype==2
label var T_SameGroup "Partner is Same Group"
gen TX_Got0xSamePerson=T_SamePerson*T_DGGot0
label var TX_Got0xSamePerson "Division Game Got 0 x Same Person"
gen TX_Got0xSameGroup=T_SameGroup*T_DGGot0
label var TX_Got0xSameGroup "Division Game Got 0 x Same Group"

regress PG_proposal T_DGGot0 T_PGNet10 T_PGNet20 T_SamePerson T_SameGroup TX_Got0xSamePerson TX_Got0xSameGroup, robust
lincom T_DGGot0+TX_Got0xSamePerson
lincom T_DGGot0+TX_Got0xSameGroup
lincom (T_DGGot0+TX_Got0xSamePerson)-(T_DGGot0+TX_Got0xSameGroup)
outreg, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","(1)") replace

regress PG_proposal T_DGGot0 T_SamePerson T_SameGroup TX_Got0xSamePerson TX_Got0xSameGroup if T_policynetpayoff==0, robust
lincom T_DGGot0+TX_Got0xSamePerson
lincom T_DGGot0+TX_Got0xSameGroup
lincom (T_DGGot0+TX_Got0xSamePerson)-(T_DGGot0+TX_Got0xSameGroup)
outreg, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","(2) Net Policy Payoff 0") merge

regress PG_proposal T_DGGot0 T_PGNet20 T_SamePerson T_SameGroup TX_Got0xSamePerson TX_Got0xSameGroup if T_policynetpayoff!=0, robust
lincom T_DGGot0+TX_Got0xSamePerson
lincom T_DGGot0+TX_Got0xSameGroup
lincom (T_DGGot0+TX_Got0xSamePerson)-(T_DGGot0+TX_Got0xSameGroup)
outreg using Table4.rtf, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","(3) Net Policy Payoff 10 or 20") merge replace

* Appendix Table A4, counts by treatment cells
bysort T_partnertype : tab T_DG_Partner_Given T_policynetpayoff

* Partitioning by own DG proposal, Appendix Table, Appendix Table A5
regress PG_proposal T_DGGot0 T_PGNet10 T_PGNet20 T_SamePerson T_SameGroup TX_Got0xSamePerson TX_Got0xSameGroup if DG_Own_Proposal==20, robust
lincom T_DGGot0+TX_Got0xSamePerson
lincom T_DGGot0+TX_Got0xSameGroup
lincom (T_DGGot0+TX_Got0xSamePerson)-(T_DGGot0+TX_Got0xSameGroup)
outreg, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","Proposed Equal Division") replace

regress PG_proposal T_DGGot0 T_PGNet10 T_PGNet20 T_SamePerson T_SameGroup TX_Got0xSamePerson TX_Got0xSameGroup if DG_Own_Proposal==40, robust
lincom T_DGGot0+TX_Got0xSamePerson
lincom T_DGGot0+TX_Got0xSameGroup
lincom (T_DGGot0+TX_Got0xSamePerson)-(T_DGGot0+TX_Got0xSameGroup)
outreg using AppendixTableA5.rtf, se squarebrack bdec(2) starlevels(10 5 1) nolegend starloc(1) varlabels sigsymbols(* ** ***) ctitles("","Proposed 40/0 Division") merge replace

* Figure 2
set scheme plotplain
graph bar (mean) PG_proposal, over(T_DG_Partner_Given, label(angle(25) labsize(small))) over(T_policynetpayoff) bar(1, fcolor(gs13) lcolor(black)) blabel(bar, position(outside) format(%9.2f)) yscale(range(0 1.05)) ytitle("Proportion Voting For Policy Proposal") xsize(8.5) ysize(11) by(T_partnertype, cols(1) note("Horizontal Axis is Division Game Outcome (Top) and Policy Game Net Policy Payoff (Bottom)", size(vsmall)))  name(figure4,replace)
graph export Figure4.pdf, replace
graph export Figure4.png, replace

log close
